import commonservice from './commonservice.js';

const Login = function(info) {
	return new Promise((resolve, reject) => {
		uni.request({
			url:commonservice.WEBSITE+'/api/_Account/Login',
			data: info,
			method: 'POST',
			//header: {
				//Content-Type:multipart/form-data
			//},
			success: function(res) {
				console.log(JSON.stringify(res))
				resolve(res);
			},
			fail: function(ex) {
				uni.showToast({
					icon: 'none',
					title: '网络异常'
				});
			}
		})
	})
}

const LoginJwt=function(info){
	return new Promise((resolve,reject)=>{
		uni.request({
			url:commonservice.WEBSITE+"/api/_Account/LoginJwt",
			data:info,
			method:'POST',
			sslVerify:false,
			success:function(res){
				resolve(res);
			},
			fail:function(ex){
				console.log(JSON.stringify(ex));
				uni.showToast({
					icon:'none',
					title:'网络异常'
				})
			}
		})
	})
}

const CheckUserInfo=function(info){
	console.log(commonservice.AccessToken)
	return new Promise((resolve,reject)=>{
		uni.request({
			url:commonservice.WEBSITE+"/api/_Account/CheckUserInfo",
			data:info,
			header:{
				'Authorization':'Bearer '+commonservice.AccessToken
			},
			method:'GET',
			success:function(res){
				resolve(res);
			},
			fail:function(ex){
				uni.showToast({
					icon:'none',
					title:'网络异常'
				})
			}
		})
	})
}

const LogOut=function(){
	return new Promise((resolve,reject)=>{
		uni.request({
			url:commonservice.WEBSITE+"/api/_Account/Logout",
			header:{
				'Authorization':'Bearer '+commonservice.AccessToken
			},
			method:'GET',
			success:function(res){
				resolve(res);
			},
			fail:function(ex){
				uni.showToast({
					title: '网络异常',
					icon:'none'
					
				});
			}
		})
	})
}

export default {
	Login: Login, //登录
	LoginJwt:LoginJwt,  //获取token
	CheckUserInfo:CheckUserInfo, //获取用户详情
	LogOut:LogOut  //退出登录
};
